package cn.xfdzx.android.apps.shop.activity.myshop;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.WebViewActivity;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.ShopInDetailsBeen;
import cn.xfdzx.android.apps.shop.bean.StoreAmountBean;
import cn.xfdzx.android.apps.shop.contract.MyShopCenterContract;
import cn.xfdzx.android.apps.shop.presenter.MyShopCenterPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.UtilsData;

/*
/* 店铺-我的账户页面
 */
public class ShopMyAccountActivity extends BaseMvpActivity<MyShopCenterPresenter> implements MyShopCenterContract.View {

    @BindView(R.id.iv_back)
    ImageView ivBack;      //标题栏-左边按钮
    @BindView(R.id.tv_allowable_amount)
    TextView tv_allowable_amount;    //可提现金额
    @BindView(R.id.tv_tx)
    TextView tv_tx;  //提现说明
    @BindView(R.id.tv_balance_amount)
    TextView tv_balance_amount;   //已完成订单金额
    @BindView(R.id.tv_frozen_amount)
    TextView tv_frozen_amount;   //进行中订单金额
    @BindView(R.id.tv_withdrawal)
    TextView tvWithdrawal;

    private int type = 0;
    private String storeId;
    private boolean is_cash_out=false;

    @Override
    public int getLayoutId() {
        return R.layout.activity_myaccount;
    }

    @Override
    public void initView() {
        mPresenter = new MyShopCenterPresenter();
        mPresenter.attachView(this);
        type = getIntent().getIntExtra("type", 0);
        storeId = UtilsData.getPreference(this, "login").getString("storeId");
//        storeId = "131351";

    }


    @Override
    protected void onStart() {
        super.onStart();
        mPresenter.getStoreAmount(storeId);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onSuccess(ShopInDetailsBeen bean) {

    }

    @Override
    public void getStoreAmountSuccess(StoreAmountBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            is_cash_out=bean.getData().isIs_cash_out();
            if (is_cash_out){
                if (type == 0) {
                    tvWithdrawal.setBackgroundResource(R.drawable.dfb9129_bg_r3);
                } else {
                    tvWithdrawal.setBackgroundResource(R.drawable.d02c557_bg_r3);
                }
            }
            tv_allowable_amount.setText("¥" + bean.getData().getAllowable_amount());
            tv_balance_amount.setText("¥" + bean.getData().getBalance_amount());
            tv_frozen_amount.setText("¥" + bean.getData().getFrozen_amount());
            if (EmptyUtil.isNotEmpty(bean.getData().getMessage())) {
                tv_tx.setText("(" + bean.getData().getMessage() + ")");
            }
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }
    Intent intent;
    @OnClick({R.id.iv_back, R.id.tv_withdrawal, R.id.iv_doubt_rules_1, R.id.iv_doubt_rules_2, R.id.iv_doubt_rules_3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:  //返回按钮点击
                finish();
                break;
            case R.id.tv_withdrawal:  //提现列表
                if (!is_cash_out){

                    return;
                }
                 intent = new Intent(this, WithdrawalListActivity.class);
                intent.putExtra("type", type);
                startActivity(intent);
                break;
            case R.id.iv_doubt_rules_1:
                intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("url", Constants.BASE_URL+"/addons/shimmer_liveshop/api/6/3/cash_out/explain?type=1");
                intent.putExtra("title", "提现规则");
                startActivity(intent);
                break;
            case R.id.iv_doubt_rules_2:
                intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("url", Constants.BASE_URL+"/addons/shimmer_liveshop/api/6/3/cash_out/explain?type=2");
                intent.putExtra("title", "提现规则");
                startActivity(intent);
                break;
            case R.id.iv_doubt_rules_3:
                intent = new Intent(this, WebViewActivity.class);
                intent.putExtra("url", Constants.BASE_URL+"/addons/shimmer_liveshop/api/6/3/cash_out/explain?type=3");
                intent.putExtra("title", "提现规则");
                startActivity(intent);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

}
